import deviceHospitalApi from '@admin/views/Monitor/Source/api/hospital/api.js'
import model from './model'

export default {
  data() {
    return {
      model: model(),
    }
  },
  methods: {
    toChange(data) {
      const { param } = this
      param.areaId = data.id
      this.model.search.regionId = data.id

      this.handleCurrentChange(1)
    },
    /**
     * @function 查询医院机电设备列表
     */
    async getList(query) {
      query.type = 3
      const res = await deviceHospitalApi.getList(query)

      this.model.faultCount = res.faultCount
      this.model.normalCount = res.normalCount
      this.model.list = res.content || []
      this.model.pagination.total = res.comQuery.totalCount
    },
    /**
     * @function 改变当前页
     * @param {Number} page -当前页
     */
    handleCurrentChange(page) {
      this.model.pagination.page = page
      this.getList({
        page: this.model.pagination.page,
        pageSize: this.model.pagination.pageSize,
        ...this.model.search,
      })
    },
    /**
     * @function 改变每页数量
     * @param {Number} page -当前页
     */
    handleSizeChange(pageSize) {
      this.model.pagination.pageSize = pageSize
      this.getList({
        page: this.model.pagination.page,
        pageSize: this.model.pagination.pageSize,
        ...this.model.search,
      })
    },
    /**
     * @function 显示设备详情对话框
     * @param {String} id -设备详情
     */
    showDetailDialog(id) {
      if (!id) return

      this.model.detailDialog.isShow = true
      this.model.detailDialog.id = id
    },
  },
}
